#include "guid.h"
#include <util/time.h>
#include <util/rand.h>

namespace gecko
{

	//---------------------------------------------------------------------------------------------

	Guid::Guid()
	{
		// generate a guid...

		// 32 bits of timestamp
		unsigned __int64 ms = (unsigned __int64)GetMilliseconds();

		// 32 bits of random noise
		static RandomNumberGenerator rnd((unsigned int)ms);
		int rand = rnd.Generate(0, 0x7fffffff - 0x1);

		m_guid = 0;
		m_guid |= rand;
		m_guid |= ms << 32;
	}

	//---------------------------------------------------------------------------------------------

	Guid::~Guid()
	{

	}

	//---------------------------------------------------------------------------------------------

	bool Guid::operator==(const Guid& rhs) const
	{
		return m_guid == rhs.m_guid;
	}

	//---------------------------------------------------------------------------------------------

	bool Guid::operator<(const Guid& rhs) const
	{
		return m_guid < rhs.m_guid;
	}

	//---------------------------------------------------------------------------------------------

	bool Guid::operator>(const Guid& rhs) const
	{
		return m_guid > rhs.m_guid;
	}

	//---------------------------------------------------------------------------------------------

}